<template>
  <div>
    <div class="address_select">
      <v-distpicker province="河南省" city="濮阳市" area="南乐县"></v-distpicker>
      <el-button style="margin-left: 20px">查询</el-button>
    </div>
    <div>
      <div style="display:flex">
      <div id="help_poverty_chart"></div>
      <div id="industry_chart"></div>
      <div id="industry_type_chart"></div>
    </div>
    <div>
      <div id="education_chart"></div>
    </div>
    </div>
  </div>
</template>

<script>
import VDistpicker from 'v-distpicker'
import echarts from 'echarts/lib/echarts'
import 'echarts/lib/chart/bar'
import 'echarts/lib/component/title'
import 'echarts/lib/component/tooltip'
import 'echarts/lib/chart/line'
import 'echarts/lib/chart/pie'
import 'echarts/lib/component/legend'
export default {
  components: {
    VDistpicker: VDistpicker
  },
  methods: {
    initPovertyChart () {
      const myChart = echarts.init(document.getElementById('help_poverty_chart'))
      const option = {
        title: {
          text: '扶贫项目'
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'shadow'
          }
        },
        xAxis: [
          {
            type: 'category',
            data: ['2016', '2017', '2018', '2019', '2020'],
            axisTick: {
              alignWithLabel: true
            }
          }
        ],
        yAxis: [{ type: 'value' }],
        series: [
          {
            name: '劳动力人数',
            type: 'bar',
            barWidth: '60%',
            data: [995, 666, 444, 858, 566]
          }
        ],
        grid: {
          top: 50,
          x: 45,
          y: 45,
          x2: 30,
          y2: 30
        }
      }
      myChart.setOption(option)
      // 建议加上以下这一行代码，不加的效果图如下（当浏览器窗口缩小的时候）。超过了div的界限（红色边框）
      window.addEventListener('resize', function () { myChart.resize() })
    },
    initIndustryChart () {
      const myChart = echarts.init(document.getElementById('industry_chart'))
      const option = {
        title: {
          text: '新增产业'
        },
        tooltip: {
          trigger: 'axis'
        },
        legend: {
          data: ['餐饮', '广告', '服饰', '培训', '娱乐']
        },
        xAxis: [
          {
            type: 'category',
            data: ['2016', '2017', '2018', '2019', '2020']
          }
        ],
        yAxis: [{ type: 'value' }],
        series: [
          {
            name: '餐饮',
            type: 'line',
            smooth: true,
            stack: '总量',
            data: [60, 100, 75, 130, 20]
          },
          {
            name: '广告',
            type: 'line',
            smooth: true,
            stack: '总量',
            data: [10, 5, 13, 8, 2]
          },
          {
            name: '服饰',
            type: 'line',
            smooth: true,
            stack: '总量',
            data: [30, 13, 21, 17, 5]
          },
          {
            name: '培训',
            type: 'line',
            smooth: true,
            stack: '总量',
            data: [20, 40, 76, 53, 13]
          },
          {
            name: '娱乐',
            type: 'line',
            smooth: true,
            stack: '总量',
            data: [20, 34, 55, 30, 10]
          }
        ],
        grid: {
          top: 50,
          x: 45,
          y: 45,
          x2: 30,
          y2: 30
        }
      }
      myChart.setOption(option)
      // 建议加上以下这一行代码，不加的效果图如下（当浏览器窗口缩小的时候）。超过了div的界限（红色边框）
      window.addEventListener('resize', function () { myChart.resize() })
    },
    initTypeChart () {
      const myChart = echarts.init(document.getElementById('industry_type_chart'))
      const option = {
        title: {
          text: '创业园产业分类'
        },
        series: [
          {
            name: '产业分类',
            type: 'pie',
            smooth: true,
            data: [
              { value: 800, name: '餐饮' },
              { value: 100, name: '广告' },
              { value: 400, name: '服饰' },
              { value: 600, name: '培训教育' },
              { value: 50, name: '娱乐' }
            ]
          }
        ]
      }
      myChart.setOption(option)
      // 建议加上以下这一行代码，不加的效果图如下（当浏览器窗口缩小的时候）。超过了div的界限（红色边框）
      window.addEventListener('resize', function () { myChart.resize() })
    },
    initEducationChart () {
      const myChart = echarts.init(document.getElementById('education_chart'))
      const option = {
        title: {
          text: '乡村劳动力学历情况'
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'cross',
            crossStyle: {
              color: '#999'
            }
          }
        },
        toolbox: {
          feature: {
            dataView: { show: true, readOnly: false },
            magicType: { show: true, type: ['line', 'bar'] },
            restore: { show: true },
            saveAsImage: { show: true }
          }
        },
        legend: {
          data: ['男性', '女性', '男女比例']
        },
        xAxis: [
          {
            type: 'category',
            data: ['初中', '高中', '中专职业院校', '大专', '本科', '硕士', '博士'],
            axisPointer: {
              type: 'shadow'
            }
          }
        ],
        yAxis: [
          {
            type: 'value',
            name: '人数',
            min: 0,
            max: 900,
            axisLabel: {
              formatter: '{value} 人'
            }
          },
          {
            type: 'value',
            name: '男女比例',
            min: 0,
            max: 25,
            interval: 5,
            axisLabel: {
              formatter: '{value} %'
            }
          }
        ],
        series: [
          {
            name: '男性',
            type: 'bar',
            data: [80, 690, 320, 150, 90, 50, 30]
          },
          {
            name: '女性',
            type: 'bar',
            data: [73, 530, 420, 130, 100, 63, 10]
          },
          {
            name: '男女比例',
            type: 'line',
            yAxisIndex: 1,
            data: [80 / 73, 690 / 530, 320 / 420, 150 / 130, 90 / 100, 50 / 63, 30 / 10]
          }
        ]
      }
      myChart.setOption(option)
      // 建议加上以下这一行代码，不加的效果图如下（当浏览器窗口缩小的时候）。超过了div的界限（红色边框）
      window.addEventListener('resize', function () { myChart.resize() })
    }
  },
  mounted () {
    this.initPovertyChart()
    this.initIndustryChart()
    this.initTypeChart()
    this.initEducationChart()
  }
}
</script>

<style lang="less" scoped>
.address_select{
  width: 700px;
  line-height: 40px;
  display: flex;
}
#help_poverty_chart{
  width: 30%;
  height: 270px;
  margin: 10px 10px;
  background-color: white;
}
#industry_chart{
  width: 50%;
  height: 270px;
  margin: 10px 10px;
  background-color: white;
}
#industry_type_chart{
  width: 30%;
  height: 270px;
  margin: 10px 10px;
  background-color: white;
}
#education_chart{
  width: 98.5%;
  height: 350px;
  margin: 10px 10px;
  background-color: white;
}
</style>
